package com.wujian.love.controller;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.wujian.love.utils.CronUtils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.util.Calendar;
import java.util.Date;

/**
 * @ClassName: TestMainController
 * @Description:
 * @Author: wuj
 * @Date: 2021-01-13 11:16
 **/
public class TestMainController {

    private static final String timeStr = "0 30 8 * * ?";

    public final static String PATTERN = "yyyy-MM-dd HH:mm:ss";

    private static final SimpleDateFormat sdf = new SimpleDateFormat(PATTERN);

    public static void main(String[] args) throws ParseException {

        String yyyyMM = DateUtil.format(new Date(), "yyyyMM");
        System.out.println(yyyyMM);

        LocalDate today = LocalDate.now();
        int dayOfMonth = today.getDayOfMonth();
        System.out.println(dayOfMonth);

        DateTime dateTime = new DateTime();
        int i = dateTime.dayOfMonth();
        System.out.println(i);

        String format = String.format("u%d", dateTime.dayOfMonth());
        System.out.println(format);


        String lastExecutionTime = CronUtils.formatZonedDateTime(CronUtils.getLastExecutionTime(timeStr));
        System.out.println("定时任务表达式时间:" + lastExecutionTime);
        long time = sdf.parse(lastExecutionTime).getTime();

        System.out.println("毫秒值:" + time);


        Calendar cal = Calendar.getInstance();
        int dayOfMoth = cal.get(Calendar.DAY_OF_MONTH);
        int moth = cal.get(Calendar.MONTH) + 25;
        if (dayOfMoth == 25) {
            if (moth == 3 || moth == 6 || moth == 9 || moth == 12) {
                System.out.println("时间匹配");
            } else {
                System.out.println("时间不匹配：月份不对");
            }
        } else {
            System.out.println("时间不匹配：不是25号");
        }
    }
}
